/**
 * 将时间数组转换为日期时间字符串
 * @param {Array} timeArray - 时间数组 [year, month, day, hour, minute, second]
 * @returns {string} 格式化后的日期时间字符串
 */
export function formatTimeArray(timeArray) {
    if (!Array.isArray(timeArray) || timeArray.length < 6) {
        return '';
    }
    const [year, month, day, hour, minute, second] = timeArray;
    return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}:${String(second).padStart(2, '0')}`;
}

/**
 * 将时间数组转换为相对时间
 * @param {Array} timeArray - 时间数组 [year, month, day, hour, minute, second]
 * @returns {string} 相对时间字符串
 */
export function getRelativeTime(timeArray) {
    if (!Array.isArray(timeArray) || timeArray.length < 6) {
        return '';
    }
    
    const [year, month, day, hour, minute, second] = timeArray;
    const date = new Date(year, month - 1, day, hour, minute, second);
    const now = new Date();
    const diff = now - date;
    
    // 转换为秒
    const seconds = Math.floor(diff / 1000);
    
    if (seconds < 60) {
        return '刚刚';
    }
    
    // 转换为分钟
    const minutes = Math.floor(seconds / 60);
    if (minutes < 60) {
        return `${minutes}分钟前`;
    }
    
    // 转换为小时
    const hours = Math.floor(minutes / 60);
    if (hours < 24) {
        return `${hours}小时前`;
    }
    
    // 转换为天
    const days = Math.floor(hours / 24);
    if (days < 30) {
        return `${days}天前`;
    }
    
    // 超过30天显示具体日期
    return formatTimeArray(timeArray);
}

/**
 * 将时间数组转换为日期字符串
 * @param {Array} timeArray - 时间数组 [year, month, day, hour, minute, second]
 * @returns {string} 格式化后的日期字符串
 */
export function formatDate(timeArray) {
    if (!Array.isArray(timeArray) || timeArray.length < 3) {
        return '';
    }
    const [year, month, day] = timeArray;
    return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
}

/**
 * 将时间数组转换为时间字符串
 * @param {Array} timeArray - 时间数组 [year, month, day, hour, minute, second]
 * @returns {string} 格式化后的时间字符串
 */
export function formatTime(timeArray) {
    if (!Array.isArray(timeArray) || timeArray.length < 6) {
        return '';
    }
    const [_, __, ___, hour, minute, second] = timeArray;
    return `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}:${String(second).padStart(2, '0')}`;
} 